package org.web2024.service.serviceimp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.web2024.dao.Result;
import org.web2024.mapper.AdminMapper;
import org.web2024.service.PublicService;
import java.util.List;
import java.util.Map;

@Service
public class PublicServiceImp implements PublicService {
    @Autowired
    private AdminMapper adminMapper;
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    @Override
    public Result getTerms() {
        if(redisTemplate.opsForValue().get("terms")==null){
            List<String> terms=adminMapper.selectTerms();
            redisTemplate.opsForValue().set("terms",terms);
            return Result.success(terms);
        }
        return Result.success(redisTemplate.opsForValue().get("terms"));
    }

    @Override
    public Map<Object, Object> currentTerm() {
        Map<Object, Object> map=redisTemplate.opsForHash().entries("currentterm");
        return  map;
    }
}
